﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Diagnostics;

namespace Microsoft.MSE.Catalog.Contracts
{
    [ServiceContract(Namespace = SC.MSENamespace)]
    public interface ICatalogCallback
    {
        [OperationContract(Action = SC.CatalogCallbackAcceptEventSoapAction, IsOneWay = true)]
        void AcceptEvent(AcceptEventRequest request);
    }

    [MessageContract()]
    public class AcceptEventRequest
    {
        [MessageBodyMember(Namespace = SC.WSENamespaceURI)]
        public MseEventData EventData;

        public AcceptEventRequest()
        {
        }

        public AcceptEventRequest(MseEventData eventData)
        {
            this.EventData = eventData;
        }
    }
    [DebuggerStepThrough]
    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public class MseEventData
    {

        private EventTopics _eventTopic;
        private List<RuntimeServerEventData> _runtimeEventData = new List<RuntimeServerEventData>();

        public MseEventData(EventTopics eventTopic)
        {
            _eventTopic = eventTopic;
        }
        [DataMember()]
        public EventTopics EventTopic
        {
            get { return _eventTopic; }
            set { _eventTopic = value; }
        }
        [DataMember(IsRequired = false)]
        public List<RuntimeServerEventData> RuntimeServers
        {
            get { return _runtimeEventData; }
            set { _runtimeEventData = value; }
        }
    }

    [DataContract(Namespace = SC.MSEEventingNamespaceURI)]
    public enum EventTopics
    {
        [EnumMember]
        RuntimeUpdated,
        [EnumMember]
        RuntimeEndpointAdded,
        [EnumMember]
        RuntimeEndpointChanged,
        [EnumMember]
        RuntimeEndpointRemoved,
        [EnumMember]
        RuntimeEndpointOperationPublished,
        [EnumMember]
        RuntimeEndpointOperationUnPublished,
        [EnumMember]
        RuntimeEndpointOperationDeActivated,
        [EnumMember]
        RuntimeEndpointOperationChanged,
        [EnumMember]
        RuntimeBindingUpdated

    }

    [DataContract(Name = "RuntimeServer", Namespace = SC.MSEEventingNamespaceURI)]
    public class RuntimeServerEventData
    {
        private List<EndpointEventData> _endpoints = new List<EndpointEventData>();
        [DataMember(IsRequired=true)]
        public string Id { get; set; }
        [DataMember(Name="Endpoints", IsRequired=false)]
        public List<EndpointEventData> Endpoints
        {
            get { return _endpoints; }
            set { _endpoints = value; }
        }
    }
    [DataContract(Name = "Endpoint", Namespace = SC.MSEEventingNamespaceURI)]
    public class EndpointEventData
    {
        private List<OperationEventData> _operations = new List<OperationEventData>();
        [DataMember(IsRequired = true)]
        public string Id { get; set; }
        [DataMember(Name = "Operations", IsRequired=false)]
        public List<OperationEventData> Operations
        {
            get { return _operations; }
            set { _operations = value; }
        }
    }
    [DataContract(Name="Operation", Namespace=SC.MSEEventingNamespaceURI)]
    public class OperationEventData
    {
        [DataMember(IsRequired = true)]
        public string Id { get; set; }
    }
}
